/**
 * 手术管理初始化
 */
var CdcSurgery = {
    id: "CdcSurgeryTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcSurgery.initColumn = function () {
    return [
        {title: '序号',width:50,formatter: function (value, row, index) {return index+1;}},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '编码', field: 'code', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '类型', field: 'busSurgType.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '状态', field: 'busSurgStatus.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '手术开始日期', field: 'startDate', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '手术结束日期', field: 'endDate', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '科室', field: 'surgLoc.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '主刀医生', field: 'surgDoc.name', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '一助', field: 'assi1st.name', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '二助', field: 'assi2nd.name', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '切口等级', field: 'busSurgInci.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '愈合情况', field: 'busSurgHeal.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '麻醉方式', field: 'busSurgAnes.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '麻醉医生', field: 'anesDoc.name', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: 'ASA评分', field: 'asaScore', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: 'NNIS分级', field: 'nnisGrade', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '术前外周WBC计数', field: 'wbcCount', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '切口个数', field: 'inciCount', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '是否使用窥镜', field: 'isEndoscope', align: 'center', valign: 'middle', sortable: true, width:100,formatter:function(value,row,index) {
            return value?"是":"否";
        }},
        {title: '是否有植入物', field: 'isImplants', align: 'center', valign: 'middle', sortable: true, width:100,formatter:function(value,row,index) {
            return value?"是":"否";
        }},
        {title: '失血量', field: 'bloodLose', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '输血量', field: 'bloodGet', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '术后并发症', field: 'complication', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '业务数据类型', field: 'data.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true, width:100,formatter:function(value,row,index) {
            return value?"是":"否";
        }}
    ];
};

/**
 * 检查是否选中
 */
CdcSurgery.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcSurgery.seItem = selected[0];
        return true;
    }
};

CdcSurgery.query = function () {
    if ((EpisodeIDTable.selEpisode)&&(EpisodeIDTable.selEpisode.id)) {
        var queryData=queryData = '{"NotQuery":"false","episodeId":"' + EpisodeIDTable.selEpisode.id + '"}';
        queryData = JSON.parse(queryData);
        CdcSurgery.table.clear();
        CdcSurgery.table.refresh({ query: queryData });
    }else{
        Sys.info('请先选择患者！' );
    }
};

$(function () {
    var defaultColunms = CdcSurgery.initColumn();
    var table = new BSTable(CdcSurgery.id, Sys.backendPath + "/cdc/cdcsurgery/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(20);
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setSubHead(30);
    table.setQueryParams({ NotQuery: true });
    CdcSurgery.table = table.init();
    CdcSurgery.query();
});
